Fix up timezones on GPX input. Combination of Park, Fouts, and myself.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 8 Jan 2003 15:58:23 +0000 (15:58 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Wed, 8 Jan 2003 15:58:23 +0000 (15:58 +0000)
gpsbabel/gpx.c
gpsbabel/util.c

index b73c84302d7a694dd1941f125065db4799b3bf8c..98af66274f336b57cc1e3c9d8a83f2427c215744 100644 (file)
@@ -388,19 +388,7 @@ gpx_end(void *data, const char *el)
                        tm.tm_mon -= 1;
                        tm.tm_year -= 1900;
                        tm.tm_isdst = 1;
-                       wpt_tmp->creation_time = mktime(&tm);
-#if 0
-                       /* mktime assumes local time, and Z is gmtime */
-                       /* localtime will initialize timezone and daylight */
-                       /* 12/31/02 - RJL - unfortunately, this fix relies
-                        * on non-ANSI extensions, so I've turned this off
-                        * and reverted to the old way.
-                        */
-                       localtime( &wpt_tmp->creation_time );
-                       wpt_tmp->creation_time -= timezone - (daylight?3600:0);
-#else
-                        wpt_tmp->creation_time = mktime(&tm);
-#endif
+                        wpt_tmp->creation_time = mktime(&tm) + get_tz_offset();
                }
                if (in_wpt && in_gs_type && !in_gs_log) {
                        wpt_tmp->gc_data.type = gs_mktype(cdatastr);
index c74a6084aceb3d02baa0b463ab1e8975c557c4d1..3e64373c898870ddf0b38b84d9c4c9b2add8fb86 100644 (file)
@@ -106,6 +106,7 @@ fprintdms(FILE *file, const coord *c, int is_lat)
        }
        fprintf(file, "%c%f\t", d, fabs(c->degrees));
 }
+
 void
 fatal(const char *fmt, ...)
 {
@@ -195,3 +196,20 @@ si_round( double d )
                return (signed int)(d+0.5);
        }
 }
+
+/*
+ *  Return a time_t suitable for adding to a time_t that is in GMT to
+ *  make it a local time.
+ */
+signed int 
+get_tz_offset(void)
+{
+       time_t now = time(0);
+       time_t later = mktime(gmtime(&now));
+
+       if (later == -1) {
+               return 0;
+       } else {
+               return (signed int) difftime(now, later);
+       }
+}